package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     *
     * 查询购物车是否已经存在该菜品
     */
    ShoppingCart list(ShoppingCart shoppingCart);

    /**
     * 更新购物车
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    int update(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     * @param shoppingCart
     */
    @Update("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) values (#{name}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount},#{image}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据用户id查询购物车数据
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> select(Long currentId);

    /**
     * 根据菜品或套餐id查询购物车数据
     * @param shoppingCart
     * @return
     */
    @Select("select * from shopping_cart where dish_id = #{dishId} or setmeal_id = #{dishId}")
    ShoppingCart getByDishOrSetmealId(ShoppingCart shoppingCart);

    /**
     * 根据id删除购物车数据
     * @param id
     */
    @Update("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);


    /**
     * 清空购物车
     */
    @Update("delete from shopping_cart where user_id = #{userId}")
    void clean(long userId);
}
